<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Shortgroup extends Model
{
    protected $table = 'short_group';
    protected $primaryKey = 'id';
    
    public static function getShortGroup($openid)
    {
        return self::select("group_id","name")->where("openid",$openid)->get();
    }

    public static function shortGroupAdd($openid,$group_id,$name)
    {
        return self::insert(["openid"=>$openid,"group_id"=>$group_id,"name"=>$name,"created_at"=>time()]);
    }

    public static function shortGroupUpdate($openid,$group_id,$name)
    {
        return self::where("openid",$openid)->where("group_id",$group_id)->update(["name"=>$name]);
    }

    public static function groupNameExist($openid,$name)
    {
        return self::where("openid",$openid)->where("name",$name)->first();
    }

    public static function shortGroupDetial($group_id)
    {
        return self::where("group_id",$group_id)->first();
    }

    public static function shortGroupDel($openid,$group_id)
    {
        return self::where("openid",$openid)->where("group_id",$group_id)->delete();
    }
}